package com.gears_software.bbnetwork.activitys;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.annotations.sharedpreferences.Pref;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.view.KeyEvent;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.avos.avoscloud.AVAnalytics;
import com.gears_software.bbnetwork.R;
import com.gears_software.bbnetwork.datas.finders.IBBNetworkFinder;
import com.gears_software.bbnetwork.datas.finders.impl.IBBNetworkFinderImpl;
import com.gears_software.bbnetwork.dialogs.StyleDialog;
import com.gears_software.bbnetwork.dialogs.StyleDialog.IStyleDialogResult;
import com.gears_software.bbnetwork.utlis.ActivityUtils;
import com.gears_software.bbnetwork.utlis.BBNetworkSharedPref_;
import com.gears_software.bbnetwork.utlis.ToastUI;

/**
 * 主页
 * 
 * @author DY-PC
 * 
 */
@EActivity(R.layout.activity_main)
@WindowFeature(Window.FEATURE_NO_TITLE)
public class MainActivity extends ActionBarActivity {

	@ViewById
	LinearLayout image_layout;

	@ViewById
	LinearLayout image_layout2;
	
	@Pref
	BBNetworkSharedPref_ sp;

	int image[] = { R.drawable.bb_number_black_1, R.drawable.bb_number_black_0,
			R.drawable.bb_number_black_7, R.drawable.bb_number_black_6,
			R.drawable.bb_number_black_3 };
	int image2[] = { R.drawable.bb_number_red_3, R.drawable.bb_number_red_9,
			R.drawable.bb_number_red_1, R.drawable.bb_number_red_4 };

	
	
	@AfterViews
	void oncreate() {
		ActivityUtils.listActivity.add(this);
		for (int i = 0; i < image.length; i++) {
			ImageView images = new ImageView(this);
			images.setImageResource(image[i]);
			image_layout.addView(images);
		}

		for (int i = 0; i < image2.length; i++) {
			ImageView images = new ImageView(this);
			images.setImageResource(image2[i]);
			image_layout2.addView(images);
		}

	}

	// 提现
	@Click
	void relative_tixian() {
		Intent intent = new Intent(this, TiXianActivity_.class);
		startActivity(intent);
	}

	// 我的点击事件
	@Click
	void layout_my() {
		Intent i = new Intent(this, MyActivity_.class);
		startActivity(i);
	}

	// 新增
	@Click
	void image_add() {
		String status = sp.status().get();
		if(status.equals("2")){
			Intent i = new Intent(this, BaoDanActivity_.class);
			startActivity(i);
		}else{
			final StyleDialog dialog = new StyleDialog(this, R.style.MyDialog);
			dialog.setOnIstyleDialogResult(new IStyleDialogResult() {
				@Override
				public void returnCode(int type) {
					if(type==0){
						dialog.dismiss();
					}
					if(type==1){
						Intent i = new Intent(MainActivity.this, MyInfoActivity_.class);
						startActivity(i);
						dialog.dismiss();
					}
				}
			});
			dialog.show();
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		AVAnalytics.onResume(this);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AVAnalytics.onPause(this);
	}

	private long mExitTime;
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if ((System.currentTimeMillis() - mExitTime) > 2000) {
				Object mHelperUtils;
				Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
				mExitTime = System.currentTimeMillis();
			} else {
				finish();
			}
			return true;
		}

		return super.onKeyDown(keyCode, event);

	}
	
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		ActivityUtils.listActivity.remove(this);
	}
	

}
